#include "qdoublespinboxhost.h"

#include "qcommonstruct.h"
#include "qabstractproperty.h"
#include "qpropertyfactory.h"

#include <QDoubleSpinBox>

using namespace SHAREDLIB;

QDoubleSpinBoxHost::QDoubleSpinBoxHost(QObject *object):
    QAbstractSpinBoxHost(object)
{
    QAbstractProperty *pro;

    pro=QPropertyFactory::createProperty("Float");
    if(pro!=NULL)
    {
        pro->setAttribute("name","maximum");
        pro->setAttribute("property_name",tr("Maximum"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Float");
    if(pro!=NULL)
    {
        pro->setAttribute("name","minimum");
        pro->setAttribute("property_name",tr("Minimum"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Float");
    if(pro!=NULL)
    {
        pro->setAttribute("name","value");
        pro->setAttribute("property_name",tr("Value"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Float");
    if(pro!=NULL)
    {
        pro->setAttribute("name","singleStep");
        pro->setAttribute("property_name",tr("SingleStep"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Number");
    if(pro!=NULL)
    {
        pro->setAttribute("name","decimals");
        pro->setAttribute("property_name",tr("Decimals"));
        pro->setAttribute("group","Attributes");
        addProperty(pro);
    }

    pro=QPropertyFactory::createProperty("Script");
    if(pro!=NULL)
    {
        pro->setAttribute("name","valueChanged");
        pro->setAttribute("property_name",tr("ValueChanged"));
        pro->setAttribute("group","Events");
        m_object->setProperty("valueChanged","");
        addProperty(pro);
    }

    appendMemery("value");

    QDoubleSpinBox *e=(QDoubleSpinBox*)m_object;
    connect(e,SIGNAL(valueChanged(QString)),this,SLOT(valueChanged(QString)));
}

void QDoubleSpinBoxHost::setValue(float value)
{
    setPropertyValue("value",value);
}

float QDoubleSpinBoxHost::value()
{
    return getPropertyValue("value").toFloat();
}

void QDoubleSpinBoxHost::setSingleStep(float singleStep)
{
    setPropertyValue("singleStep",singleStep);
}

float QDoubleSpinBoxHost::singleStep()
{
    return getPropertyValue("singleStep").toFloat();
}

void QDoubleSpinBoxHost::setDecimals(int decimals)
{
    setPropertyValue("decimals",decimals);
}

int QDoubleSpinBoxHost::decimals()
{
    return getPropertyValue("decimals").toInt();
}

void QDoubleSpinBoxHost::valueChanged(const QString &value)
{
    QString code=getPropertyValue("valueChanged").toString();
    if(code!="")
    {
        QMap<QString,QString> param;
        param.insert("value",value);
        emit_exec(code,param);
    }
}
